package com.zhy.springmvc.service.impl;

import com.zhy.springmvc.dao.TaskDao;
import com.zhy.springmvc.entity.Task;
import com.zhy.springmvc.service.intf.TaskService;
import com.zhy.springmvc.util.Rutil;
import com.zhy.springmvc.vo.PageBean;
import com.zhy.springmvc.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Service
public class TaskServiceImpl implements TaskService {
    @Autowired
    private TaskDao dao;
    @Override
    public R insert(Task task) {
        if (task.getTaskName() != null && task.getPerson() != null){
            if (dao.insert(task) > 0){
                return Rutil.ok();
            }
        }
              return Rutil.fail();
    }

    @Override
    public PageBean selectAll() {
        List<Task> list =dao.selectAll();
        System.out.println(list);
        return new PageBean(0,"",list.size(),list);
    }

    @Override
    public PageBean selectTaskName(String taskname) {
        List<Task> list =dao.selectTaskName(taskname);
        return new PageBean(0,taskname,list.size(),list);
    }

    @Override
    public R selecttask(Integer flag) {
        if (dao.selecttask(flag)>0){
            return Rutil.ok();
        }
        return Rutil.fail();

    }
}
